﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using IMClient.Model.UI;
using IMClient.ViewModels;

namespace IMClient.View
{
    public partial class InitiateGroupChatWindow : Window
    {
        public InitiateGroupChatWindowViewModel ViewModel { get; }
        public InitiateGroupChatWindow()
        {
            InitializeComponent();
            ViewModel = new InitiateGroupChatWindowViewModel();
            DataContext = ViewModel;
        }

        private void OnFriendSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sender is ListBox listBox)
            {
                foreach (var added in e.AddedItems)
                {
                    if (added is FriendViewModel friend)
                    {
                        ViewModel.AddToSelectedFriends(friend);
                    }
                }

                foreach (var removed in e.RemovedItems)
                {
                    if (removed is FriendViewModel friend)
                    {
                        ViewModel.RemoveFromSelectedFriends(friend);
                    }
                }
            }
        }

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ButtonState == MouseButtonState.Pressed)
            {
                DragMove(); // 拖动窗口
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
